// pages/item/item.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:27072634,
    movies:[],
    item:null
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 确保id有一个正确的值
    let id = options.id || this.data.id
    this.setData({id:id})
    
    let that = this
    // 查询云数据库，获取数据添加到movies中
    let db = wx.cloud.database()
    let collection = db.collection('in_theaters')
    collection.get({
      success:(res)=>{
        console.log(res.data[0].subjects);
        let movies = that.data.movies
        movies = movies.concat(res.data[0].subjects)
        that.setData({          movies:movies        })
      }
    })

    collection = db.collection('coming_soon')
    collection.get({
      success:(res)=>{
        console.log(res.data[0].subjects);
        let movies = that.data.movies
        movies = movies.concat(res.data[0].subjects)
        that.setData({          movies:movies        })
      }
    })

    collection = db.collection('top250')
    collection.get({
      success:(res)=>{
        console.log(res.data[0].subjects);
        let movies = that.data.movies
        movies = movies.concat(res.data[0].subjects)
        that.setData({          movies:movies        })


        let item = that.data.movies.find((value,index,array)=>{
          return array[index].id == that.data.id
        })
        console.log(item);
        that.setData({item:item})

      }
    })

   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})